#coding:utf-8
'''
Created on 2012-9-11

@author: edsion
'''
import WiMAT, logging, os

logger = logging.getLogger()
hdlr = logging.FileHandler("main.log")
formatter = logging.Formatter('%(asctime)s %(levelname)s %(message)s')
hdlr.setFormatter(formatter)
logger.addHandler(hdlr)

form = logging.Formatter('%(asctime)s %(levelname)s %(message)s')
handler = logging.StreamHandler()
handler.setFormatter(form)
logger.addHandler(handler)

logger.setLevel(logging.NOTSET)

Path = os.getcwd().decode('gbk') + u"\\"
QQBrowserUID = u"20027215"  #uid的十进制为537031189
QQBrowserAppName = u"QQ浏览器"
IAPName=u"edsion-NEWT"
symbian = WiMAT.getDevice("sp:COM3", "symbian")

if symbian.GetCurrentTime() == None :
    logger.error("Connect error!")
else:
    logger.info("Connect successfully")
#    symbian.UnInstall(QQBrowserAppName, QQBrowserUID)
    if symbian.IsAppExist(QQBrowserAppName, QQBrowserUID) == 0 :
        logger.info("%s is not existed"%QQBrowserAppName)
        symbian.Install(u"qqbrowser_3.1.0.827_s60v5.sisx", Path, QQBrowserUID)
    symbian.sleep(10)
    if symbian.GetAppIsRun(0x10281EF2): #0x10281EF2为离线模式创建连接的提示
        symbian.sendTouchEvent(70, 615)
    print symbian.SetIAPByName(IAPName)
#    print hex(symbian.getAppUid())
#    symbian.getScreenshotToFile(Path+"screen.jpg")